<!--
 * @Author: Bo Cai
 * @Mail: caibo0520@qq.com
 * @Date: 2021-12-14 23:02:34
 * @LastEditors: Bo Cai
 * @LastEditTime: 2021-12-15 16:18:59
-->
<template>
    <div class="app-container">
        <!-- 表格 -->
        <el-table :data="list" border fit highlight-current-row>
            <el-table-column prop="sort" label="排序" width="60" />

            <el-table-column prop="title" label="名称" width="180" />

            <el-table-column prop="imageUrl" label="图片">
                <!-- 图片的显示 -->
                <template slot-scope="scope">
                    <img
                        :src="scope.row.imageUrl"
                        alt=""
                        style="width: 180px; height: 90px"
                    />
                </template>
            </el-table-column>

            <el-table-column prop="linkUrl" label="图片跳转路径" width="180" />

            <el-table-column label="操作" width="200" align="center">
                <template slot-scope="scope">
                    <router-link :to="'/banner/edit/' + scope.row.id">
                        <el-button
                            type="primary"
                            size="mini"
                            icon="el-icon-edit"
                            >修改</el-button
                        >
                    </router-link>
                    <el-button
                        type="danger"
                        size="mini"
                        icon="el-icon-delete"
                        @click="deleteBannerById(scope.row.id)"
                        >删除</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import bannerApi from '@/api/banner/banner'
export default {
    data() {
        return {
            list: null,
        }
    },
    created() {
        this.getBannerListMethod()
    },
    methods: {
        getBannerListMethod() {
            bannerApi.getBannerList().then((response) => {
                this.list = response.data.bannerList
            })
        },
        deleteBannerById(id) {
            this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    return bannerApi.deleteBannerById(id)
                })
                .then(() => {
                    this.getBannerListMethod()
                    this.$message({
                        type: 'success',
                        message: '删除成功!',
                    })
                })
                .catch((response) => {
                    // 失败
                    if (response === 'cancel') {
                        this.$message({
                            type: 'info',
                            message: '已取消删除',
                        })
                    } else {
                        this.$message({
                            type: 'error',
                            message: '删除失败',
                        })
                    }
                })
            //
        },
    },
}
</script>
